<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
        <el-form-item label="仓库编号" prop="warehouseCode">
          <el-input
            v-model="queryParams.warehouseCode"
            placeholder="请输入仓库编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="仓库名称" prop="warehouseName">
          <el-input
            v-model="queryParams.warehouseName"
            placeholder="请输入仓库名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商编号" prop="vendorCode">
          <el-input
            v-model="queryParams.vendorCode"
            placeholder="请输入供应商编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商名称" prop="vendorName">
          <el-input
            v-model="queryParams.vendorName"
            placeholder="请输入供应商名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料编码" prop="itemCode">
          <el-input
            v-model="queryParams.itemCode"
            placeholder="请输入物料编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="物料名称" prop="itemName">
          <el-input
            v-model="queryParams.itemName"
            placeholder="请输入物料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="入库日期" prop="params">
          <el-date-picker
            clearable
            v-model="queryParams.params"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            placeholder="请选择入库日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>

      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="供应商编号" align="center" prop="vendorCode"/>
        <el-table-column label="供应商名称" align="center" prop="vendorName"/>
        <el-table-column label="物料编号" align="center" prop="itemCode"/>
        <el-table-column label="物料名称" align="center" prop="itemName"/>
        <el-table-column label="单位" align="center" prop="unitOfMeasure"/>
        <el-table-column label="仓库编号" align="center" prop="warehouseCode"/>
        <el-table-column label="仓库名称" align="center" prop="warehouseName"/>
        <el-table-column label="入库数量" align="center" prop="quantity"/>
        <el-table-column label="入库类型" align="center" prop="inventoryStatus">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.inventoryStatus === 'QUALIFIED'">正品入库</el-tag>
            <el-tag type="warning" v-if="scope.row.inventoryStatus === 'CONCESSION_ACCEPTANCE'">让步接收</el-tag>
            <el-tag type="danger" v-if="scope.row.inventoryStatus === 'SCRAP'">报废入库</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import {listCgItemRecptEnforcement} from '@/api/mes/cg/cgItemRecptEnforcement'
import Template from "@/views/print/printtemplate/list.vue";

export default {
  name: "CgItemRecptEnforcement",
  components: {Template},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      tableData: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vendorCode: null,
        vendorName: null,
        warehouseCode: null,
        warehouseName: null,
        itemCode: null,
        itemName: null,
        params: []
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购管理-采购到货单主列表 */
    getList() {
      const query = {...this.queryParams};
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      this.loading = true;
      listCgItemRecptEnforcement(query).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  },
};
</script>
